﻿using System.Data;
using Core.Library;
using DataObject;

namespace Event.Controls.News
{
    public partial class Details : System.Web.UI.UserControl
    {
        #region variables, constants, properties
        protected string SortURL;
        protected string EncodedBase64Title;
        protected string DetailedURL;
        protected string _link;
        #endregion

        internal bool DataBind(DataTable dt)
        {
            if (dt != null && dt.Rows.Count > 0)
            {
                var newsTitle = Utils.GetIdFromRequestString(Utils.NewsTitle, string.Empty);
                var r = dt.Rows[0];
                if (newsTitle != UnicodeUtility.UnicodeToKoDauAndGach(r[Constants.Table_News.News_Title].ToString()))
                    Channelvn.Cached.UrlRewrite._301Redirection._301Redirect(r[Constants.Table_News.Url].ToString());
                var avatarMeta = Utils.Photo.GetThumbImage_Zoom(
                r[Constants.Table_News.News_Image].ToString(),
                200,
                200);
                MetaKeyword.AddMetaTag(Page,string.Format("{0} | {1}", r[Constants.Table_News.News_Title], Const.Meta_Title), r[Constants.Table_News.News_Sapo].ToString());
                MetaKeyword.AddFacebookMetaTag(Page, string.Format("{0} | {1}", r[Constants.Table_News.News_Title], Const.Meta_Title), r[Constants.Table_News.News_Sapo].ToString(), r[Constants.Table_News.Url].ToString(), avatarMeta);
                this.ltrTitle.Text = r[Constants.Table_News.News_Title].ToString();
                ltrPenName.Text = r[Constants.Table_News.News_PenName].ToString();
                ltrPublishDate.Text = r[Constants.Table_News.DisplayPublishOnlyDate].ToString();
                ltrPublishTime.Text = r[Constants.Table_News.DisplayPublishOnlyTime].ToString();
                ltrSapo.Text = r[Constants.Table_News.News_Sapo].ToString();
                ltrBody.Text = r[Constants.Table_News.News_Content].ToString();
                SortURL = r[Constants.Table_News.SortUrl].ToString();
                DetailedURL = r[Constants.Table_News.Url].ToString();
                EncodedBase64Title = r[Constants.Table_News.EncodedBase64Title].ToString();
                _link = r[Constants.Table_News.Url].ToString();
                return true;
            }
            return false;
        }
    }
}